package com.changgou.system.filter.test;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.InetSocketAddress;

/**
 * @Auther: guozy
 * @Date: 2022/8/29 - 08 - 29 - 22:12
 * @Description: com.changgou.system.filter
 * @version: 1.0
 */

public class GateWayFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        String path = exchange.getRequest().getURI().getPath();
        System.out.println(path+"===>>网关第一层访问");
        InetSocketAddress address = exchange.getRequest().getRemoteAddress();
        exchange.getRequest().mutate().path(path+"123");
        System.out.println(address.getHostName()+"===>>访问ip");
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 1;
    }
}
